package com.example.demo.Controller;

import com.example.demo.Model.MessageInfo;
import com.example.demo.Service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController {
    @Autowired
    MessageService messageService;
    @RequestMapping("/getList")
   public List<MessageInfo> getList(){
       return messageService.getList();
   }
   @RequestMapping("/publish")
    public boolean publish(MessageInfo m){
        if(!StringUtils.hasLength(m.getTo())&&
       !StringUtils.hasLength(m.getMessage())&&!StringUtils.hasLength(m.getFrom())){
            return false;
        }
       // messageInfoList.add(m);
       messageService.add(m);
        return true;
   }
}
